package com.ccys.cms.service.administrator.impl;


import com.ccys.cms.service.administrator.TblUParcelSettingWebService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.administrator.TblUParcelPostalCodeExclusionDTO;
import com.ccys.db.dto.administrator.TblUParcelSettingDTO;
import com.ccys.db.entity.TblUParcelSetting;
import com.ccys.db.mapper.TblUParcelSettingMapper;
import com.ccys.db.page.PageUtils;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.vo.administrator.TblUParcelSettingWebVO;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;


/**
 * uParcel 快递设置管理
 */
@Service
@Slf4j
public class TblUParcelSettingWebServiceImpl extends BaseServiceImpl<TblUParcelSetting> implements TblUParcelSettingWebService {

    @Autowired(required = false)
    private TblUParcelSettingMapper tblUParcelSettingMapper;



    @Override
    public ResponseResult change(HttpServletRequest request, HttpServletResponse response, TblUParcelSetting entity) {
        List<String> whereList = new ArrayList<>();
        whereList.clear();
        whereList.add("del_flag=0");
        TblUParcelSetting oneByLimit = this.findOneByLimit(TblUParcelSetting.class, whereList);
        if (oneByLimit == null) {
            // 新增
            this.saveEntity(entity);
        } else {
            // 编辑
            entity.setId(oneByLimit.getId());
            this.updateEntityById(entity);
        }
        return ResponseResult.success();
    }

    @Override
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, TblUParcelSettingDTO dto) {
        TblUParcelSettingWebVO tblUParcelSettingWebVO = this.tblUParcelSettingMapper.listObjectsCms(dto);
        return ResponseResult.success(tblUParcelSettingWebVO);
    }


}